const tableName = "OwnedObject";

const records = [
    {
        "id": 1,
        "dungeonId": 123,
        "scriptId": 456,
        "chapterId": 789,
        "stageId": 321,
        "melodramaId": "undefined",
        "groupId": 654,
        "name": "这是个东西",
        "medium": "image",
        "source_md5": "2342adfa",
        "source_remote_url": "http://gw2.kongzhong.com/act/gw2pic/concept/6_b.jpg",
        "source_local_path": "_doc/uniapp_save/16905388895770.jpg",
        "usable": "false",
        "isPrivate": "false",
        "shareable": "true",
        "mustBePublished": "true",
        "ownedQuantity": 1,
        "usedQuantity": 0,
        "isNew": "true"
    },
    {
        "id": 2,
        "dungeonId": 123,
        "scriptId": 456,
        "chapterId": 789,
        "stageId": 321,
        "melodramaId": "undefined",
        "groupId": 654,
        "name": "这是个东西",
        "medium": "image",
        "source_md5": "2342adfa",
        "source_remote_url": "http://gw2.kongzhong.com/act/gw2pic/concept/6_b.jpg",
        "source_local_path": "_doc/uniapp_save/16905389295260.jpg",
        "usable": "false",
        "isPrivate": "false",
        "shareable": "true",
        "mustBePublished": "true",
        "ownedQuantity": 1,
        "usedQuantity": 0,
        "isNew": "true"
    },
    {
        "id": 3,
        "dungeonId": 123,
        "scriptId": 456,
        "chapterId": 789,
        "stageId": 321,
        "melodramaId": "undefined",
        "groupId": 654,
        "name": "这是个东西",
        "medium": "image",
        "source_md5": "2342adfa",
        "source_remote_url": "http://gw2.kongzhong.com/act/gw2pic/concept/6_b.jpg",
        "source_local_path": "_doc/uniapp_save/16905389811540.jpg",
        "usable": "false",
        "isPrivate": "false",
        "shareable": "true",
        "mustBePublished": "true",
        "ownedQuantity": 1,
        "usedQuantity": 0,
        "isNew": "true"
    },
    {
        "id": 4,
        "dungeonId": 123,
        "scriptId": 456,
        "chapterId": 789,
        "stageId": 321,
        "melodramaId": "undefined",
        "groupId": 654,
        "name": "这是个东西",
        "medium": "image",
        "source_md5": "2342adfa",
        "source_remote_url": "http://gw2.kongzhong.com/act/gw2pic/concept/6_b.jpg",
        "source_local_path": "_doc/uniapp_save/16905390170320.jpg",
        "usable": "false",
        "isPrivate": "false",
        "shareable": "true",
        "mustBePublished": "true",
        "ownedQuantity": 1,
        "usedQuantity": 0,
        "isNew": "true"
    },
    {
        "id": 5,
        "dungeonId": 123,
        "scriptId": 456,
        "chapterId": 789,
        "stageId": 321,
        "melodramaId": "undefined",
        "groupId": 654,
        "name": "这是个东西",
        "medium": "image",
        "source_md5": "2342adfa",
        "source_remote_url": "http://gw2.kongzhong.com/act/gw2pic/concept/6_b.jpg",
        "source_local_path": "_doc/uniapp_save/16905390432810.jpg",
        "usable": "false",
        "isPrivate": "false",
        "shareable": "true",
        "mustBePublished": "true",
        "ownedQuantity": 1,
        "usedQuantity": 0,
        "isNew": "true"
    },
    {
        "id": 6,
        "dungeonId": 123,
        "scriptId": 456,
        "chapterId": 789,
        "stageId": 321,
        "melodramaId": "undefined",
        "groupId": 654,
        "name": "这是个东西",
        "medium": "image",
        "source_md5": "2342adfa",
        "source_remote_url": "http://gw2.kongzhong.com/act/gw2pic/concept/6_b.jpg",
        "source_local_path": "_doc/uniapp_save/16905390900440.jpg",
        "usable": "false",
        "isPrivate": "false",
        "shareable": "true",
        "mustBePublished": "true",
        "ownedQuantity": 1,
        "usedQuantity": 0,
        "isNew": "true"
    },
    {
        "id": 7,
        "dungeonId": 123,
        "scriptId": 456,
        "chapterId": 789,
        "stageId": 321,
        "melodramaId": "undefined",
        "groupId": 654,
        "name": "这是个东西",
        "medium": "image",
        "source_md5": "2342adfa",
        "source_remote_url": "http://gw2.kongzhong.com/act/gw2pic/concept/6_b.jpg",
        "source_local_path": "_doc/uniapp_save/16905393239820.jpg",
        "usable": "false",
        "isPrivate": "false",
        "shareable": "true",
        "mustBePublished": "true",
        "ownedQuantity": 1,
        "usedQuantity": 0,
        "isNew": "true"
    },
    {
        "id": 8,
        "dungeonId": 123,
        "scriptId": 456,
        "chapterId": 789,
        "stageId": 321,
        "melodramaId": "undefined",
        "groupId": 654,
        "name": "这是个东西",
        "medium": "image",
        "source_md5": "2342adfa",
        "source_remote_url": "http://gw2.kongzhong.com/act/gw2pic/concept/6_b.jpg",
        "source_local_path": "_doc/uniapp_save/16905393621930.jpg",
        "usable": "false",
        "isPrivate": "false",
        "shareable": "true",
        "mustBePublished": "true",
        "ownedQuantity": 1,
        "usedQuantity": 0,
        "isNew": "true"
    },
    {
        "id": 9,
        "dungeonId": 123,
        "scriptId": 456,
        "chapterId": 789,
        "stageId": 321,
        "melodramaId": "undefined",
        "groupId": 654,
        "name": "这是个东西",
        "medium": "image",
        "source_md5": "2342adfa",
        "source_remote_url": "http://gw2.kongzhong.com/act/gw2pic/concept/6_b.jpg",
        "source_local_path": "_doc/uniapp_save/16905393729360.jpg",
        "usable": "false",
        "isPrivate": "false",
        "shareable": "true",
        "mustBePublished": "true",
        "ownedQuantity": 1,
        "usedQuantity": 0,
        "isNew": "true"
    },
    {
        "id": 10,
        "dungeonId": 123,
        "scriptId": 456,
        "chapterId": 789,
        "stageId": 321,
        "melodramaId": "undefined",
        "groupId": 654,
        "name": "这是个东西",
        "medium": "image",
        "source_md5": "2342adfa",
        "source_remote_url": "http://gw2.kongzhong.com/act/gw2pic/concept/6_b.jpg",
        "source_local_path": "_doc/uniapp_save/16905407236240.jpg",
        "usable": "false",
        "isPrivate": "false",
        "shareable": "true",
        "mustBePublished": "true",
        "ownedQuantity": 1,
        "usedQuantity": 0,
        "isNew": "true"
    }
]

const OwnedObject = {
	init: function() {
		let tableStructure =
			`
			id INTEGER PRIMARY KEY AUTOINCREMENT,
			dungeonId INTEGER NOT NULL,
			scriptId INTEGER NOT NULL,
			chapterId INTEGER NOT NULL,
			stageId INTEGER NOT NULL,
			melodramaId INTEGER NOT NULL,
			groupId INTEGER NOT NULL,
			name VARCHAR(80) NOT NULL,
			medium VARCHAR(10) NOT NULL,
			source_md5 VARCHAR(10) NOT NULL,
			source_remote_url TEXT NOT NULL,
			source_local_path TEXT NOT NULL,
			usable Booean NOT NULL,
			isPrivate Booean NOT NULL,
			shareable Booean NOT NULL,
			mustBePublished Booean NOT NULL,
			ownedQuantity TINYINT NOT NULL,
			usedQuantity TINYINT NOT NULL
			`;
		
	},
	add: function(dungeonId,scriptId,chapterId,stageId,melodramaId,groupId,name,medium,
			source_md5,source_remote_url,source_local_path,usable,isPrivate,shareable,mustBePublished,ownedQuantity) {
		let insertSql =
			`insert into ${tableName}(dungeonId,scriptId,chapterId,stageId,melodramaId,groupId,name,medium,
			source_md5,source_remote_url,source_local_path,usable,isPrivate,shareable,mustBePublished,ownedQuantity,usedQuantity) 
			values ("${dungeonId}","${scriptId}","${chapterId}","${stageId}","${melodramaId}","${groupId}","${name}","${medium}"
			,"${source_md5}","${source_remote_url}","${source_local_path}","${usable}","${isPrivate}","${shareable}","${mustBePublished}","${ownedQuantity}",0)`;
		console.log("Prepare sql:" + insertSql);
	},
	listByChapters: function(chapterIds, callback) {
		callback(records);
	},
	listByGroups: function(groupIds, callback) {
		callback(records);
	},
	check: function(objectId) {
		let updateSql = `update ${tableName} set isNew=false where id = ${objectId}`;
		console.log("Prepare sql:" + updateSql);
	},
}

export {
	OwnedObject
}